package com.qf.service.api;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Map;

/**
 * @author 何星宇
 * @version V1.0
 * @Date 2021/11/23 20:17
 */

@FeignClient(value = "sms-platform-cache")
public interface CacheService {
    /**
     * 获取key-hash
     * @param key
     * @return
     */
    @RequestMapping(value = "/cache/hmget/{key}", method = RequestMethod.GET)
    public Map hMGet(@PathVariable("key") String key);

    /**
     * 获取key-hash的某个filed
     * @param key
     * @param filed
     * @return
     */
    @RequestMapping(value = "/cache/hget/{key}/{filed}", method = RequestMethod.GET)
    public String hGet(@PathVariable("key") String key,
                       @PathVariable("filed") String filed);

    /**
     * 通过key获取string的value
     * @param key
     * @return
     */
    @RequestMapping(value = "/cache/get/{key}", method = RequestMethod.GET)
    String get(@PathVariable("key") String key);

    /**
     * 自增数据
     * @param key
     * @param delta 每次自增多少
     * @return
     */
    @RequestMapping(value = "/cache/incr", method = RequestMethod.GET)
    Long incr(@RequestParam("key") String key,
              @RequestParam("delta") long delta);

    /**
     * 存储key-string，并设置生存时间
     * @param key
     * @param value
     * @param expireSecond
     * @return
     */
    @RequestMapping(value = "/cache/save2cache", method = RequestMethod.POST)
    boolean set(@RequestParam("key") String key,
                @RequestParam("value") Object value,
                @RequestParam("expireSecond") Long expireSecond);

    /**
     * 针对key设置生存时间
     * @param key
     * @param expireSecond
     * @return
     */
    @RequestMapping(value = "/cache/expire", method = RequestMethod.POST)
    boolean expire(@RequestParam("key") String key,
                   @RequestParam("expireSecond") Long expireSecond);
}
